package com.base.cn.platform.os.entity.course.cou;

import com.base.cn.platform.os.common.mybatis.BaseEntity;
import lombok.Data;

import java.util.Objects;

/**
 * 课程扩展数据
 *
 * @author s.li
 * @create 2018-05-23-10:30
 */
@Data
public class CourseProfile extends BaseEntity {
    /**购买数量*/
    private Integer buyCount;
    /**查看数量*/
    private Integer viewCount;
    /**评论数量*/
    private Integer commentCount;
    /**问题数量*/
    private Integer questionCount;
    /**笔记数量*/
    private Integer noteCount;
    /**播放次数*/
    private Integer playCount;
    /**收藏数*/
    private Integer favoritesCount;
    /**课程质量*/
    private Float quality;
    /**教学质量*/
    private Float teach;
    /**综合感受*/
    private Float feel;
    /**综合评分*/
    private Float multiple;

    public void addQuality(Integer quality) {
        if (Objects.isNull(this.quality)) {
            this.quality = 0.0F;
        }
        float sum = this.quality * (commentCount - 1) + quality;
        this.quality = Math.round((sum / commentCount * 100)) / 100.0F;
    }

    public void addTeach(Integer teach) {
        if (Objects.isNull(this.teach)) {
            this.teach = 0.0F;
        }
        float sum = this.teach * (commentCount - 1) + teach;
        this.teach = Math.round((sum / commentCount * 100)) / 100.0F;
    }

    public void addFeel(Integer feel) {
        if (Objects.isNull(this.feel)) {
            this.feel = 0.0F;
        }
        float sum = this.feel * (commentCount - 1) + feel;
        this.feel = Math.round((sum / commentCount * 100)) / 100.0F;
    }

    public void calculateMultiple() {
        float sum = this.feel + this.quality + this.teach;
        this.multiple = Math.round((sum / 3 * 100)) / 100.0F;
    }
}
